package com.songshuang.nomina.service.impl;

import com.songshuang.nomina.service.BabyNamingService;
import com.songshuang.nomina.vo.BabyInfoVO;
import com.songshuang.nomina.vo.BabyNameResVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class BabyNamingServiceImpl implements BabyNamingService {

    private final Random random = new Random();

    @Override
    public List<BabyNameResVO> traditionNaming(BabyInfoVO babyInfoVO) {
        List<BabyNameResVO> babyNames = new ArrayList<>();

        // 获取父亲的姓氏
        String fatherName = babyInfoVO.getFatherName();
        String surname = fatherName.substring(0, 1); // 假设姓氏是名字的第一个字符

        // 示例名字片段
        String[] boyNames = {"明", "伟", "强", "杰", "洋"};
        String[] girlNames = {"华", "敏", "丽", "娜", "欣"};

        // 根据性别选择名字数组
        String[] namesToChooseFrom = babyInfoVO.getGender().equals("男") ? boyNames : girlNames;

        // 生成名字
        for (int i = 0; i < 3; i++) {
            BabyNameResVO nameResVO = new BabyNameResVO();
            String name = generateRandomName(surname, namesToChooseFrom);
            nameResVO.setName(name);
            nameResVO.setDetails("随机生成的名字"); // 这里可以添加生成名字的原因
            babyNames.add(nameResVO);
        }

        return babyNames;
    }

    private String generateRandomName(String surname, String[] nameFragments) {
        int length = random.nextInt(2) + 2; // 随机生成2或3个字的名字
        StringBuilder name = new StringBuilder(surname);

        for (int i = 0; i < length - 1; i++) {
            int index = random.nextInt(nameFragments.length);
            name.append(nameFragments[index]);
        }

        return name.toString();
    }
}
